<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <title>用户管理系统 - 用户列表</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
        .container { width: 90%; max-width: 1200px; margin: 0 auto; }
        h1 { color: #333; text-align: center; }
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            margin: 5px;
        }
        .btn:hover { background-color: #45a049; }
        .btn-danger { background-color: #f44336; }
        .btn-danger:hover { background-color: #d32f2f; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }
        th { background-color: #f2f2f2; font-weight: bold; }
        tr:hover { background-color: #f9f9f9; }
        .pagination { margin-top: 20px; text-align: center; }
        .pagination a { display: inline-block; padding: 8px 16px; text-decoration: none; color: #4CAF50; }
        .pagination a.active { background-color: #4CAF50; color: white; border-radius: 5px; }
        .pagination a:hover:not(.active) { background-color: #f1f1f1; border-radius: 5px; }
    </style>
</head>
<body>
<div class="container">
    <h1>用户管理系统 - 用户列表</h1>
    <a href="${pageContext.request.contextPath}/" class="btn">返回首页</a>
    <a href="${pageContext.request.contextPath}/user/add" class="btn">新增用户</a>

    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>密码</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${users}" var="user">
            <tr>
                <td>${user.userId}</td>
                <td>${user.userName}</td>
                <td>${user.password}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/user/edit/${user.userId}" class="btn">编辑</a>
                    <a href="${pageContext.request.contextPath}/user/delete/${user.userId}" class="btn btn-danger"
                       onclick="return confirm('确定要删除这个用户吗？')">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <!-- 分页导航 -->
    <div class="pagination">
        <c:if test="${currentPage > 1}">
            <a href="${pageContext.request.contextPath}/user/list?page=1&pageSize=3">首页</a>
            <a href="${pageContext.request.contextPath}/user/list?page=${currentPage-1}&pageSize=3">上一页</a>
        </c:if>

        <c:forEach begin="1" end="${totalPages}" var="pageNum">
            <c:if test="${pageNum == currentPage}">
                <a class="active" href="#">${pageNum}</a>
            </c:if>
            <c:if test="${pageNum != currentPage}">
                <a href="${pageContext.request.contextPath}/user/list?page=${pageNum}&pageSize=3">${pageNum}</a>
            </c:if>
        </c:forEach>

        <c:if test="${currentPage < totalPages}">
            <a href="${pageContext.request.contextPath}/user/list?page=${currentPage+1}&pageSize=3">下一页</a>
            <a href="${pageContext.request.contextPath}/user/list?page=${totalPages}&pageSize=3">末页</a>
        </c:if>
    </div>
</div>
</body>
</html>